package com.mb.app.controller;

import com.mb.app.domain.TbMemberInfo;
import com.mb.app.service.ITbMemberInfoService;
import com.mb.common.utils.DateUtils;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import com.mb.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会员表  前端控制器
 * </p>
 *
 * @author zwl
 * @since 2019-04-22
 */
@Controller
@RequestMapping("/app/member")
@Slf4j
public class TbMemberInfoController {


    @Autowired
    private ITbMemberInfoService memberInfoService;

    @GetMapping("/index")
    String index(){
        return "/app/member/member_list";
    }


    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        // 时间截取
        String regTime = (String) params.get("regTime");
        if (StringUtils.isNotEmpty(regTime)) {
            params.put("startTime", DateUtils.parse(regTime.substring(0,10),DateUtils.DATE_PATTERN));
            params.put("endTime",regTime.substring(13,23)+" 23:59:59");
        }
        Query query = new Query(params);
        List<TbMemberInfo> list = memberInfoService.queryList(query);
        int total = memberInfoService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }


    @ResponseBody
    @PostMapping("/remove")
    public R remove(@RequestParam("memberId") Long memberId, HttpServletRequest request){
        int result = memberInfoService.remove(memberId);
        return R.ok();
    }

    @ResponseBody
    @PostMapping("/status")
    public R status(@RequestParam("memberId") Long memberId,@RequestParam("status") Integer status){
        int result = memberInfoService.status(memberId,status);
        return R.ok();
    }


}
